package com.zhengping.zpys.security.product;

import com.zhengping.zpys.base.AjaxResult;
import com.zhengping.zpys.security.role.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author chenweizuan
 * @description This is description of class
 * @version 1.0
 * @date 2020/4/1 0:28
 */
@RestController
@RequestMapping("/monitor/product")
public class ProductController {

    @Autowired
    ProductService productService;

    @RequestMapping("/createProduct")
    public AjaxResult createProduct(@RequestBody(required = false) Product product){
        Integer row = productService.createProduct(product);
        return AjaxResult.success(row);
    }

    @RequestMapping("/updateProduct")
    public AjaxResult updateProduct(@RequestBody(required = false) Product product){
        Integer row = productService.updateProduct(product);
        return AjaxResult.success(row);
    }

    @RequestMapping("/queryProductListByCategoryId")
    public AjaxResult queryProductListByCategoryId(@RequestParam(required = false) Long categoryId){
        List<Product> products = productService.queryProductListByCategoryId(categoryId);
        return AjaxResult.success(products);
    }

    @RequestMapping("/queryProductListByName")
    public AjaxResult queryProductListByName(@RequestParam(required = false) String productName){
        List<Product> products = productService.queryProductListByName(productName);
        return AjaxResult.success(products);
    }

    @RequestMapping("/queryProductListByProductId")
    public AjaxResult queryProductListByProductId(@RequestParam(required = false) Long productId){
        Product product = productService.queryProductListByProductId(productId);
        return AjaxResult.success(product);
    }

    @RequestMapping("/deleteProductList")
    public AjaxResult deleteProductList(@RequestBody(required = false) Long[] productIds){
        Integer row = productService.deleteProductList(productIds);
        return AjaxResult.success(row);
    }
}
